{{extend ("./layout")}}

{{#block ("body")}}
    
    <!-- 列表内容 -->
    <div class="panel panel-default">
          <div class="panel-heading">
              <ol class="breadcrumb">
                <li><a href="#">首页</a></li>
                <li><a href="#">视频</a></li>
                <li class="active">列表</li>
              </ol>
          </div>

          <div class="panel-heading">
              <div class="input-group">
                <span class="input-group-addon">视频标题</span>
                <input type="text" id = "searchId" style="width:300px;margin-right:10px;" class="form-control" value = "{{keyword}}" placeholder="请输入是查找的视频标题">
                <input type="button" class="btn btn-primary" onclick="search();" style="margin-right:10px;" value="查找">
                <input type="button" class="btn btn-primary" id = "addId" onclick="window.location.href = '/video/add' " value="新增">
              </div>
          </div>

          <div class="panel-body">
                <div>
                  <!-- 表格 -->
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th>#</th>
                        <th>标题</th>
                        <th>排序号</th>
                        <th>视频Id</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                    <tbody>
                        {{#each(list)}}
                            <tr>
                                <td>{{this.vid}}</td>
                                <td>{{this.vtitle}}</td>
                                <td>{{this.vsortno}}</td>
                                <td>{{this.vvideoid}}</td>
                                <td>
                                  <input type="button" class="btn btn-success" onclick="window.location.href = '/video/edit/{{this.vid}}'" value="编辑"> | 
                                  <input type="button" class="btn btn-danger" onclick="javascript:deleteVideo({{this.vid}})" value="删除"> 
                                </td>
                          </tr>
                        {{/each}}
                    </tbody>
                  </table>
                </div>

                <div>
                  <nav>
                    <ul class="pagination">
                      {{#if( currentPage===0 )}}
                         <li class="disabled"><a href="#">&laquo;</a></li>
                      {{else}}
                         <li><a href="/video/list?pageIndex={{pageIndex-1}}&pageSize={{pageSize}}&currentPage={{currentPage-1}}&keyword={{keyword}}">&laquo;</a></li>
                      {{/if}}

                      
                      {{#each(pages)}}
                            {{#if( currentPage === this )}}
                                <li class="active"><a href="/video/list?pageIndex={{this}}&pageSize={{pageSize}}&currentPage={{this}}&keyword={{keyword}}">{{this+1}}</a></li>
                            {{else}}
                                <li><a href="/video/list?pageIndex={{this}}&pageSize={{pageSize}}&currentPage={{this}}&keyword={{keyword}}">{{this+1}}</a></li>
                            {{/if}}
                      {{/each}}

                      {{#if( currentPage===pageCount-1 )}}
                         <li class="disabled"> <a href="#">»</a> </li>
                      {{else}}
                         <li><a href="/video/list?pageIndex={{pageIndex+1}}&pageSize={{pageSize}}&currentPage={{currentPage+1}}&keyword={{keyword}}">»</a></li>
                      {{/if}}

                      
                   </ul>
                 </nav>
                </div>
           </div>
    </div>

    <script type="text/javascript">
        function search(){
            window.location.href = '/video/list?pageIndex=0&pageSize={{pageSize}}&currentPage=0&keyword='+$("#searchId").val();
        }

        function deleteVideo(vid){
            if(confirm("确定要删除吗?")){
                $.getJSON('/video/delete/'+vid,null,function(jsObj){
                    if (jsObj.status=='1') {
                        alert("删除成功!!!"); 
                    }else{
                        alert("删除失败!!!");
                    }

                    window.location.href = "/video/list?pageIndex=0&pageSize={{pageSize}}&currentPage=0&keyword={{keyword}}";
                });
            };
        }
    </script>
{{/block}}